<template>
    <view class="content">
        <view class="top">
            <view class="padding-lr-sm">
                <u-search placeholder="搜索内容" v-model="keyword" :show-action="false" height="70" @search="doSearch"></u-search>
            </view>
            <timeSearch @doSearch="doSearch" />
        </view>
        
        <view class="box" v-for="(item, index) in list" :key="index" @click="$gTo(`/pages/house-plan/check-record-child?id=${item.id}`)">
            <view class="u-flex">
                <view class="text-lg text-bold u-flex-1">{{item.name}}</view>
                <!-- order_status 0-未完  1-已完 -->
                <view class="drug-state1" v-if="item.order_status == 1">已盘点</view>
                <view class="drug-state2" v-if="item.order_status == 0">未盘点</view>
            </view>
            <view class="text-df text-gray">
                <view class="u-p-t-5" v-if="item.member">盘点人：{{item.member}}</view>
                <view class="u-p-t-5" v-if="item.finish_time">盘点时间：{{ item.finish_time.split(' ')[0] }}</view>
            </view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
                keyword: '',
                startTime: '',
                endTime: '',
            };
        },
        onShow() {
            this.page = 1;
            this.list = [];
            this.status = 'loadmore';
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            
            doSearch(data) {
                if (data) {
                    this.startTime = data.startTime
                    this.endTime = data.endTime
                }
                this.page = 1;
                this.list = [];
                this.status = 'loadmore';
                this.getList()
            },
            
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('inventorys/plan_list', {
                    userToken: this.$getSync('userToken'),
                    page: this.page,
                    limit: 10,
                    keywords: this.keyword,
                    start_time: this.startTime,
                    end_time: this.endTime,
                }).then(ret => {
            		if (ret.status == 0) {
                        if (ret.data.length > 0) {
                        	this.list = this.list.concat(ret.data);
                        	this.page++;
                        	this.status = 'loadmore'
                        } else {
                        	this.status = 'nomore'
                        }
            		} else {
            			this.$toast(ret.message);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    
    page{
        background-color: #f5f5f5 !important;
    }
    .content{
        padding-bottom: 150rpx;
    }
    .top{
        background-color: #fff;
    }
    
    .box{
        background-color: #fff;
        border-radius: 15rpx;
        padding: 30rpx 25rpx;
        margin: 25rpx 25rpx 0;
        word-break: break-all;
        white-space: pre-line;
    }
    
    .drug-state1{
        font-size: 24rpx;
        color: #0075ff;
        padding: 9rpx 12rpx;
        background-color: #ebf4fe;
        border-radius: 8rpx;
        margin-left: 20rpx;
    }
    .drug-state2{
        font-size: 24rpx;
        color: #00c28f;
        padding: 9rpx 12rpx;
        background-color: #e9fbf6;
        border-radius: 8rpx;
        margin-left: 20rpx;
    }
    
    .down{
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
    }
    .drug-btn{
        color: #fff;
        padding: 10rpx 20rpx;
        background-color: #8392a5;
        border-radius: 8rpx;
        margin-left: 20rpx;
    }

</style>
